/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package worms;

import java.util.Random;


/**
 *
 * @author isen
 */
public abstract class Item {
    public int x;
    public int y;
    private int counterItem=0;
    private Random nbreAléatoire=new Random();

    public GameGrid carte=null;

    
    //generate
    public Item() {
    }
    
    public Item(GameGrid carte) {
        this.carte=carte;
        this.counterItem++;
        position();
    }

    
    
    
    //methods
    public void apparaître(){
        this.carte.addMap(worms.Item.this, this.x, this.y);
    }
    
    public void disparaître(){
        this.carte.deleteMap(worms.Item.this,this.x, this.y);
    }
    
    private void position(){
        do{
        this.x= 1+this.nbreAléatoire.nextInt(9);
        this.y= 1+this.nbreAléatoire.nextInt(9);
        }while(this.carte.caseVide(this.x, this.y)==0);
    }


    @Override
    protected void finalize() throws Throwable {
        this.counterItem--;
        try{
           
                     
        }finally{
        super.finalize();
        }
       
    }
   
    
}
